import { BaseWindow } from "../../../../component/window/BaseWindow";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { Language } from "../../../../../extend/language/Language";
import { ObjCreate } from "../../common/ObjCreate";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { ImagesConst } from "../../../resource/ImagesConst";
import { TilePanel } from "../../equipment/TilePanel";
import { PetCpnTopCellRenderer } from "./PetCpnTopCellRenderer";
import { PageSelecter } from "../../common/pageSelect/PageSelecter";
import { SPetArenaInfos } from "../../../../../Message/Game/SPetArenaInfos";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { EPetArenaSearch } from "../../../../../Message/Game/EPetArenaSearch";
import { _searchType } from "../../../../../this/_searchType";
type int = number;
//class PetCpnTopWindow
    
    export  class PetCpnTopWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this.setSize(360, 355);
            this.title = Language.getString(54650);
            this.titleHeight = 28;
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            ObjCreate.createBg(17, 39, 325, 305, this);
            ObjCreate.createTextField(Language.getString(54679), 30, 50, 200, 20, this, GlobalStyle.textFormat2);
            ObjCreate.createTextField(Language.getString(54680), 140, 50, 200, 20, this, GlobalStyle.textFormat2);
            this._myServerTxt = ObjCreate.createTextField("", 255, 50, 200, 20, this, GlobalStyle.textFormatGreen);
            this._myServerTxt.htmlText = Language.getString(54723);
            this._myServerTxt.addEventListener(flash.events.TextEvent.LINK, this.onMyServerClickHandler);
            ObjCreate.createBg(25, 75, 290, 2, this, ImagesConst.SplitLine);
            this._topList = new TilePanel();
            this._topList.setSize(315, 270);
            this._topList.columnWidth = 315;
            this._topList.rowHeight = 40;
            this._topList.setStyle("cellRenderer", PetCpnTopCellRenderer);
            this._topList.move(25, 75);
            this.addChild(this._topList);
            this._pageBar = new PageSelecter();
            this._pageBar.mode = PageSelecter.CompleteMode;
            this._pageBar.x = (360 - this._pageBar.width) / 2;
            this._pageBar.y = 320;
            this._pageBar.addEventListener(flash.events.Event.CHANGE, this.onCurPageChangeHandler);
            this.addChild(this._pageBar);
            return;
        }

        public updateBySPetArenaInfos(arg1: SPetArenaInfos): void
        {
            this._petArenaInfos = arg1;
            if (arg1) 
            {
                this.updateData(arg1.petArenaInfos);
                this._pageBar.maxPage = arg1.totalPage;
            }
            return;
        }

        public refresh(): void
        {
            this.searchArrangeListByPage(this._pageBar.currentPage);
            return;
        }

        /* internal  */updateData(arg1: Array<any>): void
        {
            this._topList.dataProvider = new DataProvider(arg1);
            return;
        }

        /* internal  */onCurPageChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=this._pageBar.currentPage;
            this.searchArrangeListByPage(loc1);
            return;
        }

        /* internal  */searchArrangeListByPage(arg1: int): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.PetCpnSearch, {"searchType": _searchType, "perPage": 6, "targetPage": arg1}));
            return;
        }

        /* internal  */onMyServerClickHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=0;
            if (this._linkSearchType != EPetArenaSearch._EPetArenaSearchLocalHero) 
            {
                loc1 = EPetArenaSearch._EPetArenaSearchLocalHero;
                this._myServerTxt.htmlText = Language.getString(54723);
            }
            else 
            {
                loc1 = EPetArenaSearch._EPetArenaSearchHero;
                this._myServerTxt.htmlText = Language.getString(54724);
            }
            this._searchType = this._linkSearchType;
            this._pageBar.updatePageTxt(1);
            this.searchArrangeListByPage(1);
            this._linkSearchType = loc1;
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            this._searchType = EPetArenaSearch._EPetArenaSearchHero;
            this._pageBar.updatePageTxt(1);
            this.searchArrangeListByPage(1);
            return;
        }

        /* internal */ /* var */_myServerTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_topList: TilePanel;

        /* internal */ /* var */_pageBar: PageSelecter;

        /* internal */ /* var */_petArenaInfos: SPetArenaInfos;

        /* internal */ /* var */_searchType: int=1;

        /* internal */ /* var */_linkSearchType: int=5;
    }
